shouzhi = {}

G_HUD = nil
G_HUD_TIME = 0
G_HUD_STATE = true



----------------------------------
----------------------------------
----------   分辨率  --------------
----------------------------------

fenBianLv = {}

fenBianLv.devX = 1080;
fenBianLv.devY = 1920;

--运行信息
fenBianLv.runX, fenBianLv.runY = getScreenSize()
-- 倍率
fenBianLv.rotX = fenBianLv.runX /  fenBianLv.devX;
fenBianLv.rotY = fenBianLv.runY /  fenBianLv.devY;

function fenBianLv.devToRun_x(num)
  return  math.ceil(fenBianLv.rotX * num)
end

function fenBianLv.devToRun_y(num)
    return math.ceil(fenBianLv.rotY * num)
end

function fenBianLv.runToDev_x(num)
    return math.ceil(num / fenBianLv.rotX )
end

function fenBianLv.runToDev_Y(num)
    return math.ceil(num / fenBianLv.rotY )
end

----------------------------------
----------------------------------
---------- 附加方法  --------------
----------------------------------
G_DO_While = false;


-- doWhile 变种
-- fun 方法变量
-- useDoWhileFlag 使用 G_DO_While,如果为true,需要在fun中修改 G_DO_While 的值
function doWhile(fun, useDoWhileFlag)
    if useDoWhileFlag then
        G_DO_While = true;
        while G_DO_While do
            G_DO_While = fun()
        end
        G_DO_While = false;
    else
        local flag = true;
        while flag do
            flag = fun()
        end
    end
end

-- 点击命令
function shouzhi.click(x, y, sleepTime)
    if sleepTime == nil then
        sleepTime = 50
    end
    touchDown(2, x, y);
    mSleep(sleepTime);
    touchUp(2, x, y);
end

function shouzhi.click2()
    shouzhi.click(x, y)
end


-- 手指移动
function shouzhi.move(x, y, eX, eY, step)
    touchDown(1, x, y)


    local diffX = x - eX;
    local diffY = y - eY;

    local tempX = x;
    local tempY = y;


    if step == nil then
        step = 50
    end

    local index = 0
    while not (tempX == eX) or not (tempY == eY) do

        index = index + 1;
        -- x
        if diffX > 0 then
            tempX = tempX - 50
            if tempX < eX then
                tempX = eX
            end
        else
            tempX = tempX + 50
            if tempX > eX then
                tempX = eX
            end
        end

        -- y
        if diffY > 0 then
            tempY = tempY - 50
            if tempY < eY then
                tempY = eY
            end
        else
            tempY = tempY + 50
            if tempY > eY then
                tempY = eY
            end
        end
        --toast(tostring(tempX)..","..tostring(tempY))
        mSleep(30)
        touchMove(1, tempX, tempY)
    end

    mSleep(50)
    touchUp(1, eX, eY)
end

--曲线滑动
function ParabolaMove(x,y,x2,y2,step,stepTime_ms)
local step = step or 2
local stepTime_ms = stepTime_ms or 2
if x>x2 then
step = 0-step
end

math.randomseed(tostring(os.time()):reverse():sub(1, 6))
x = x+math.random(-3,3)
y = y+math.random(-3,3)
x2 = x2+math.random(-3,3)
y2 = y2+math.random(-3,3)
local h=x;
local k=y;
local a = (y2-k)/((x2-h)*(x2-h))
local tmpx = x
if math.random(-3,3) < 0 then
h=x2;
k=y2;
a = (y-k)/((x-h)*(x-h))
end

local tmpy = a*(tmpx-h)*(tmpx-h) + k


touchDown(1, tmpx , tmpy)
while true do
if math.abs(tmpx-x2) >= math.abs(step) then 
tmpy = a*(tmpx-h)*(tmpx-h) + k
touchMove(1, tmpx,tmpy)
mSleep(stepTime_ms)
else
break
end
tmpx = tmpx + step
end

touchMove(1, x2,y2)
mSleep(stepTime_ms)
touchUp(1, x2, y2)

end

-- 到int
function toInt(num)
    return math.ceil(num)
end


-- 比较两个对象的值是否相等
function equalsObject(obj1, obj2)
    local flag = false;
    flag = obj1 == obj2;

    if flag then
        return flag
    end
    return tostring(flag) == tostring(flag)
end


